/*
*  Copyright 2019-2023 CY
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.xiao.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.xiao.domain.CgUserTem;
import me.zhengjie.modules.xiao.domain.vo.CgUserTemQueryCriteria;
import me.zhengjie.modules.xiao.service.CgUserTemService;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
* @author cui
* @date 2024-10-28
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "用户通知表管理")
@RequestMapping("/api/cgUserTem")
public class CgUserTemController {

    private final CgUserTemService cgUserTemService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    public void exportCgUserTem(HttpServletResponse response, CgUserTemQueryCriteria criteria) throws IOException {
        cgUserTemService.download(cgUserTemService.queryAll(criteria), response);
    }

    @GetMapping(value = "/page")
    @Log("查询用户通知表")
    @ApiOperation("查询用户通知表")
    public ResponseEntity<PageResult<CgUserTem>> queryCgUserTem(CgUserTemQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(cgUserTemService.queryAll(criteria,page),HttpStatus.OK);
    }

    @GetMapping(value = "/findByUser")
    @Log("查询登录用户通知状态")
    @ApiOperation("查询登录用户通知状态")
    public ResponseEntity<CgUserTem> findByUser(){
        Long userId = SecurityUtils.getCurrentUserId();
        return new ResponseEntity<>(cgUserTemService.getById(userId),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增用户通知表")
    @ApiOperation("新增用户通知表")
    public ResponseEntity<Object> createCgUserTem(@Validated @RequestBody CgUserTem resources){
        cgUserTemService.create(resources);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PutMapping
    @Log("修改用户通知表")
    @ApiOperation("修改用户通知表")
    public ResponseEntity<Object> updateCgUserTem(@Validated @RequestBody CgUserTem resources){
        cgUserTemService.update(resources);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @DeleteMapping
    @Log("删除用户通知表")
    @ApiOperation("删除用户通知表")
    public ResponseEntity<Object> deleteCgUserTem(@RequestBody List<Integer> ids) {
        cgUserTemService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}